package com.atguigu

import org.apache.flink.api.scala._

/**
 * @ClassName WordCount
 * @Description 批处理计算
 * @Author Mr Yang
 * @Date 2020/8/19 21:39
 * @Version 1.0
 */
object WordCount {
  def main(args: Array[String]): Unit = {

    //创建一个批处理的执行环境
    val env = ExecutionEnvironment.getExecutionEnvironment

    //从文件中读取数据
    val inputPath = "F:\\work\\FlinkTutorial\\src\\main\\resources\\hello.txt"
    val inputDataSet = env.readTextFile(inputPath)

    //分词之后count
    val wordCountDataSet = inputDataSet.flatMap(_.split(" "))
      .map((_,1))
      .groupBy(0)
      .sum(1)

    //打印输出
    wordCountDataSet.print()
  }
}
